<script type="text/javascript" src="<?php echo base_url('assets/js/ajaxupload.js');?>"></script>
<div class="width735">
<div class="box_edit">
    <form method="post" name="EditUser" id="EditUser" enctype="multipart/form-data" action="<?php echo site_url('usercp/ca-nhan') ?>">
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Họ và tên </span>
            <input name="fullname" class="text float_l input" type="text" id="fullname" value="<?php echo $member['fullname']; ?>">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Địa chỉ </span>
            <input name="address" class="text float_l input" type="text" id="address" value="<?php echo @$member['address'] ?>">
        </div>
        <div class="shop_personal_style_form clear">
            <span class="shop_personal_laber">Ngày sinh </span>
            <input type="text" class="float_l hasDatepicker text input" id="birthday" name="birthday" value="" >
        </div>
        <div class="shop_personal_style_form clear">
            <span class="shop_personal_laber">Số CMT </span>
            <input type="text" class="float_l text input" id="cmt" name="cmt" value="<?php echo @$member['cmt'] ?>" maxlength="9">
        </div>
        <div class="shop_personal_style_form clearfix">
            <span class="shop_personal_laber">Điện thoại bàn </span>
            <input class="text float_l input" name="home_phone" type="text" id="home_phone" value="<?php echo @$member['phone'] ?>" maxlength="20">
            <span class="notice clearfix float_l mr_t_4">(Phải có mã vùng. VD: 0439743410)</span>
        </div>
        <div class="shop_personal_style_form clear">
            <span class="shop_personal_laber"></span>
            <input value="1" <?php if(!empty($member[''])){ echo 'checkded'; } ?> id="show_home_phone" class="check_box float_l" type="checkbox" name="show_home_phone">
            <span class="float_l" style="margin: 2px 5px">Hiển thị số điện thoại</span>
        </div>
        <div class="shop_personal_style_form clear">
            <span class="shop_personal_laber">Fax </span>
            <input class="text float_l input" name="fax" type="text" id="fax" value="<?php echo @$member['fax'] ?>" maxlength="20">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Di động </span>
            <input name="mobile" class="text float_l input" type="text" id="mobile" value="<?php echo @$member['mobile'] ?>" maxlength="20">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">YahooID </span>
            <input name="yahoo" class="text float_l input" type="text" id="yahoo" value="<?php echo @$member['yahoo'] ?>" maxlength="50">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">SkypeID </span>
            <input name="skype" class="text float_l input" type="text" id="skype" value="<?php echo @$member['skype'] ?>" maxlength="50">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Email </span>
            <input name="email" class="text float_l input" readonly="true" type="text" id="email" value="<?php echo $member['email'] ?>" maxlength="100">
        </div>
        <div class="shop_personal_style_form clear">
            <span class="shop_personal_laber"></span>
            <input value="1" id="hide_email" class="check_box float_l" type="checkbox" name="hide_email" <?php if(!empty($member['hide_email'])){ echo "checked"; } ?>>
            <span class="float_l" style="margin: 2px 5px">Hiển thị Email </span>
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber"></span>
            <input value="1" id="email_alert" class="check_box float_l input" type="checkbox" name="email_alert" <?php if(!empty($member['is_alert'])){ echo 'checked="checked"';} ?>>&nbsp;&nbsp;
            <span class="float_l" style="margin: 2px 5px">Nhận Email thông báo</span><br>
            <span class="notice float_l">Tích vào đây để nhận các thông báo, tin nhắn, phản hồi tới bạn  ( nếu có ) mỗi ngày!</span>
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Website </span>
            <input name="website" type="text" id="website" class="text float_l input" value="<?php echo @$member['website'] ?>" maxlength="100">
        </div>
        <div class="shop_personal_style_form">
            <span class="shop_personal_laber">Thông tin liên hệ</span>
            <textarea name="contact" id="contact" cols="40" rows="4" class="textarea"><?php echo @$member['contact']; ?></textarea>
            <span class="notice clearfix float_l mr_t_4">(Hiển thị duới mỗi bài viết)</span>
        </div>
        <div class="shop_personal_style_form clearfix">
            <span class="shop_personal_laber">Ảnh Avatar</span>
            <input type="file" name="userfile" class="float_l" id="upload-button">
            <span class="notice float_l mr_t_4 clear left">(Ảnh định dạng *.jpg, *.jpeg, *.gif và không quá 2Mb)</span>
            <input name="avatar" type="hidden" id="avatar" value="">
        </div>
        <div class="shop_personal_style_form clear">
            <div class="shop_avatar_user" id="upload-div">
                <img src="<?php echo base_url(thumb($member['avatar'],160,160)) ?>" onerror="this.src='<?php echo base_url('medias/images/noavatar.jpg') ?>'" >

            </div>
        </div>
        <div id="personalSubmit" class="shop_personal_submit float_l clear">
            <input id="update" class="btn_sumit" name="update" type="submit" value="Lưu xác nhận">&nbsp;&nbsp;
            <input class="btn_sumit" name="reset" type="reset" value="Nhập lại">
        </div>
    </form>
</div>
</div>
 <script type="text/javascript">
     jQuery(document).ready(function(){
         //load image da upload truoc day, tu cookie
         loadUploadedImages();
         jQuery('#loader').hide();
         new AjaxUpload('upload-button', {
             action: '<?php echo base_url("upload/avatar");?>',
             responseType: 'json',
             onChange : function(file , ext) {
                 return true;
             },
             onSubmit : function(file , ext){
                 var images = Get_Cookie( 'postimages' ) ;
                 if(images!=null){
                     images = images.split(";");
                     if(images.length>10){
                         alert('Bạn chỉ được phép upload 10 ảnh/1 tin');
                         return false;
                     }
                 }
                 // Allow only images. You should add security check on the server-side.
                 if (ext && /^(gif|jpg|jpeg|png)$/i.test(ext)){
                     /* Change status text */
                     //$('#upload-div .text').text('Uploading ' + file);
                     jQuery('#loader_overlay').show();
                     jQuery('#loader').show();
                 } else {
                     // extension is not allowed
                     jQuery('#msg').text('Bạn chỉ được phép upload file ảnh gif,jpg,png,jpeg');
                     // cancel upload
                     return false;
                 }
             },
             onComplete : function(file, response){
                 jQuery('#loader').hide();
                 jQuery('#loader_overlay').hide();
                 var randomnumber= "thumb_" + Math.floor(Math.random()*11);
                 if (response && /^(success)/i.test(response.status)) {
                     $('#avatar').val(response.file_url);
                     jQuery('#upload-div').html('<img class="avatar100"  src="'+base_url + response.file_url+'">'+'<span class="delete-image"><a title="Xóa ảnh này!" class="gallery" onclick="return del_image(\''+response.file_url+'\', \''+ randomnumber +'\');" href="javascript:void(0)">Xóa</a></span>');
                     // Chen anh vao cookie
                     if ( Get_Cookie( 'avatar' ) ){
                         del(Get_Cookie( 'avatar' ));
                         Set_Cookie( 'avatar', response.file_url, '', '/', '', '' );
                     }
                     else{
                         response.file_url = response.file_url;
                         Set_Cookie( 'avatar', response.file_url, '', '/', '', '' );
                     }
                 } else {
                     alert('Lỗi tải ảnh '+file+'! \n'+ response.issue);
                     $('#upload-div .text').html('Upload FAILED');
                 }
             }
         });
     });

     function loadUploadedImages(){
     <?php
     if(empty($member['avatar'])){
         ?>
         if ( Get_Cookie( 'avatar' ) ) {

             var images = Get_Cookie( 'avatar' ) ;
             if(images!=null){
                 $('#avatar').val(images);
                 $('#upload-div').html('<img class="avatar100" src="'+base_url+images+'">'+ '<span class="delete-image"><a onclick="return del_image(\''+images+'\');" href="javascript:void(0)"><img src="'+base_url+'assets/default/image/icon/delete.png"></a></span>');
             }
         }
       <?php } ?>
     }

     // Xoa anh tren server
     function del_image(url){
         if ( confirm("Bạn có muốn xóa ảnh này?") ) {
             $.post("<?php echo site_url('/post/deleteimage');?>", { 'imgurl': url}, function(data) {
                 // Xoa anh khoi cookie
                 $('#upload-div img').attr('src','./medias/images/post_item_no_image.jpg');
                 if( Get_Cookie("postimages") ) {
                     $('#images').val();
                     Set_Cookie( 'postimages', "", '', '/', '', '' );
                 }
             } );
         }
         return false;
     }
     function del(url){
         $.post("<?php echo site_url('/post/deleteimage');?>", { 'imgurl': url}, function(data) { } );
         return false;
     }
 </script>